package server;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Server1 {
    private ServerSocket serverSocket;

    public Server1() {
        try {
            System.out.println("正在启动服务端>>>");
            serverSocket = new ServerSocket(8089);
            System.out.println("服务端启动成功!");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public void start(){
        try {
            System.out.println("等待连接客户端>>>");
            Socket socket = serverSocket.accept();
            System.out.println("客户端连接成功!");
            InputStream in = socket.getInputStream();
            InputStreamReader isr = new InputStreamReader(in,"UTF-8");
            BufferedReader br = new BufferedReader(isr);
            String line;
            while ((line = br.readLine())!=null){
                System.out.println("客户端:"+line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        Server1 server1 = new Server1();
        server1.start();
    }
}
